<?php
/**
 * Created by PhpStorm.
 * User: Mizuki
 * Date: 2019/7/9
 * Time: 20:07
 */
namespace Api\Logic;

/**
 * 文档模型逻辑层公共模型
 * 所有逻辑层模型都需要继承此模型
 */
class BaseLogic {
    public $result = ['success' => FALSE, 'msg' => '', 'data' => NULL, 'errCode' => -1];

    public function __construct ()
    {
    }

    public function setError ($msg, $errCode = 4003, $data = NULL)
    {
        $this->result['success'] = FALSE;
        $this->result['msg'] = $msg;
        $this->result['data'] = $data;
        $this->result['errCode'] = $errCode;
        return $this->result;
    }

    public function setSuccess ($msg = '', $errCode = 0, $data = NULL)
    {
        $this->result['success'] = TRUE;
        $this->result['msg'] = $msg;
        $this->result['data'] = $data;
        $this->result['errCode'] = $errCode;
        return $this->result;
    }

    public function hasMorePage ($total_count, $page = 0, $page_size = 20)
    {
        $has_more = FALSE;
        if (!is_numeric($page) || !is_numeric($page_size) || $page <= 0 || $page_size <= 0) {
            $has_more = FALSE;
        }
        if ($total_count <= 0) {
            $has_more = FALSE;
        }
        $total_page = ceil($total_count / $page_size);
        $has_more = $page < $total_page ? TRUE : FALSE;

        $this->result['uid'] = get_uid() ? TRUE : FALSE;
        $this->result['page'] = $page;
        $this->result['page_size'] = $page_size;
        $this->result['total_count'] = $total_count;
        $this->result['has_more'] = $has_more;
    }

}